package c2.group.server.schedule;

import c2.advanced.server.configuration.AdvServerEnv;
import c2.group.business.GroupBody;
import cp.solution.business.game.status.GroupStatusReport;
import cp.solution.util.device.IpTools;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;

@Slf4j
@Configuration
@EnableScheduling
public class ReportSchedule {

    @Autowired
    GroupBody groupBody;
    @Autowired
    AdvServerEnv env;

    private static long runningId = System.currentTimeMillis();

    @Scheduled(fixedDelay=3000)
    private void reportToConsole() {
        try {
            log.debug("向console汇报");
            GroupStatusReport report = new GroupStatusReport();
            report.runningId = runningId;
            report.groupCode = groupBody.getCode();
            report.groupName = "--";
            report.excelMode = env.getSelf().getExcelPath();
            report.hostList = IpTools.getIpV4List();
            report.webScheme = "--";
            report.webPort = -1;
            report.cloudServerCode = "--";
            report.version = GroupBody.version();
            report.detail = "暂无";
            groupBody.api.reportGroupStatus(report);
        } catch (Exception e) {
            log.error("向console汇报发生异常:", e);
        }
    }
}